package ClientDB;

import java.io.IOException;
import java.io.ObjectOutputStream;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class WaitWindow {

    private Shell shell;
    private Button back;
    private Image background;
    private Font font;
    private ObjectOutputStream out = null;
    

    public WaitWindow(Shell shell, ObjectOutputStream out) {
    	this.out = out;
        FormLayout layout = new FormLayout();
        this.shell = shell;
        this.background = new Image(shell.getDisplay(), "wait.jpg");
        this.font = new Font(shell.getDisplay(), "Monotype Corsiva", 14, SWT.ITALIC);
        shell.setBackgroundImage(background);
        shell.setBounds(background.getBounds());
        shell.setText("Waiting for player...");        
        shell.setLocation(250, 250);
        shell.setLayout(layout);
        createButtons();
        addButtonListeners();
        addButtonToolTips();
        
        
    }

    private FormData locateButton(int width, int height, int top1, int top2,
            int left1, int left2) {
        FormData result = new FormData(width, height);
        result.top = new FormAttachment(top1, top2);
        result.left = new FormAttachment(left1, left2);
        return result;
    }

    private void addButtonListeners() {
        back.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
            	try {
					out.writeObject((Boolean) true);
				} catch (IOException e1) {
				}
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                
            }
        });

    }

    private void addButtonToolTips() {
        back.setToolTipText("Are you sure?");
    }

    private void createButtons() {
        this.back = new Button(shell, SWT.FLAT);
        back.setText("Back");
        back.setFont(font);
        FormData quitGameFD = locateButton(90, 32, 10, 33, 35, 15);
        back.setLayoutData(quitGameFD);
    }
    
}